//
//  TestCell.m
//  BTable
//
//  Created by adiljan on 16/3/30.
//  Copyright © 2016年 adiljan. All rights reserved.
//

#import "TestCell.h"

@implementation TestCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

//  Cell的构造方法
+ (instancetype)creatWithTitle :(NSString *)title inTableView :(UITableView *)tableView
{
    TestCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:kNilOptions].lastObject;
    }
    cell.longLabel.text = title;
    return cell;
}

/**
 *  拿到bottomCub的最大Y值并返回
 */
- (CGFloat)cellHeight
{
    //  强制布局之前，需要先手动设置下cell的真实宽度，以便于准确计算
    CGRect rect = self.frame;
    rect.size.width = [[UIScreen mainScreen] bounds].size.width;
    self.frame = rect;
    [self layoutIfNeeded];    //  一定要强制布局下，否则拿到的高度不准确
    return CGRectGetMaxY(self.longLabel.frame);
}

@end
